package org.yx.service.smfr.view_process_path;

import org.dbist.dml.Page;
import org.dbist.dml.Query;
import org.yx.models.SmfrProPth;
import org.yx.utils.BaseService;

import com.xiaoleilu.hutool.util.StrUtil;

/**
 * 查询工艺路线
 * @author zxw
 * @since 2018/03/30
**/
public class SmfrViewProcessPathService extends BaseService {
	public SmfrViewProcessPathOut viewProcessPath(SmfrViewProcessPathIn in) throws Exception {
		Query query = new Query(in.getPageIndex(), in.getPageSize());
		query.addFilter("orgCode", in.getUserOrgCode());
		if (!StrUtil.isBlank(in.getPathFilter())) {
			Query orQuery = new Query();
			orQuery.addFilter("pathCode", "like", in.getPathFilter() + "%");
			orQuery.addFilter("pathDesc", "like", in.getPathFilter() + "%");
			orQuery.setOperator("or");
			query.addFilters(orQuery);
		}

		if (!StrUtil.isBlank(in.getPathCode())) {
			query.addFilter("pathCode", in.getPathCode());
		}
		query.addOrder("pathCode", true);

		Page<SmfrProPth> pathPage = selectPage(SmfrProPth.class, query);

		SmfrViewProcessPathOut out = new SmfrViewProcessPathOut();
		out.setTotalSize(pathPage.getTotalSize());
		out.setPathList(pathPage.getList());

		return out;
	}
}